package com.jeesite.modules.wx.web;


import com.alibaba.fastjson.JSONObject;
import com.jeesite.modules.wx.entity.WxBusinessApply;
import com.jeesite.modules.wx.service.WxBusinessApplyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangjianxin
 */
@RestController
@RequestMapping("/business")
@Slf4j
public class BusinessController {

    @Autowired
    private WxBusinessApplyService wxBusinessApplyService;

    /**
     * 想加盟
     * @param businessName
     * @param businessPeople
     * @param businessPhone
     * @param businessAddress
     * @return
     */
    @RequestMapping("/sign")
    public JSONObject sign(@RequestParam(value = "businessName") String businessName,
                           @RequestParam(value = "businessPeople") String businessPeople,
                           @RequestParam(value = "businessPhone") String businessPhone,
                           @RequestParam(value = "businessAddress") String businessAddress){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result","1");

        WxBusinessApply wxBusinessApply = new WxBusinessApply();
        wxBusinessApply.setName(businessName);
        wxBusinessApply.setPeople(businessPeople);
        wxBusinessApply.setPhone(businessPhone);
        wxBusinessApply.setAddress(businessAddress);

        try {
            wxBusinessApplyService.insert(wxBusinessApply);

        }catch (Exception e){
            e.getLocalizedMessage();
            log.error("想加盟插入错误={}",e.getMessage());
            jsonObject.put("result","0");
        }

        return  jsonObject;
    }
}
